<?php

namespace App\Controllers;

use App\Services\MoneyService;
use App\Services\WithdrawAuditService;
use Illuminate\Http\Request;

class MoneyController extends BaseController
{
    public $allows = [];

    //额度转化接口
    public function MoneyExchange(Request $request)
    {
        $this->validate($request, [
            'hall_id' => 'required',//厅ID
            'user_id' => 'required',//用户id
            'partner_id' => 'required',//子钱包partner_id
            'amount' => 'required',//额度转化金额,单位:厘
            'type' => 'required|in:1,2',//额度转化类型1-主转子 2-子转主
        ]);
        $params = [
            'hall_id' => $request->input('hall_id'),
            'user_id' => $request->input('user_id'),
            'partner_id' => $request->input('partner_id'),
            'amount' => $request->input('amount'),
            'type' => $request->input('type'),
            'remark' => $request->input('remark', ''),//备注
            'create_admin_id' => $request->input('create_admin_id', 0),
            'is_manual' => $request->input('is_manual', 0),//是否人工存提 0 不是 1 是  默认 0
        ];
        return MoneyService::exchange($params);
    }

    //处理第三方转账单据
    public function handleTransfer(Request $request)
    {
        $this->validate($request, [
            'money_transfer_id' => 'required',//转账记录id
            'status' => 'required',//处理目标状态 成功状态不允许修改
        ]);
        $params = [
            'money_transfer_id' => $request->input('money_transfer_id'),
            'status' => $request->input('status'),
            'remark' => $request->input('remark', ''),
        ];
        return MoneyService::handleTransfer($params);
    }

    //获取余额
    public function getbalance(Request $request)
    {
        $this->validate($request, [
            'hall_id' => 'required',//厅ID
            'user_id' => 'required',//用户id
            'api_name' => 'required',//用户id
        ]);
        $params = [
            'hall_id' => $request->input('hall_id'),
            'user_id' => $request->input('user_id'),
            'api_name' => $request->input('api_name'),
        ];
        return MoneyService::getUserBalance($params);
    }

    // 同步子钱包
    public function sysncChildWalletBalance(Request $request)
    {
        $this->validate($request, [
            'hall_id' => 'required',//厅ID
            'user_id' => 'required',//用户id
            'api_name' => 'required',//用户id
        ]);
        $params = [
            'hall_id' => $request->input('hall_id'),
            'user_id' => $request->input('user_id'),
            'api_name' => $request->input('api_name'),
        ];
        return MoneyService::sysncUserChildWalletBalance($params);
    }

    //  获取稽核列表
    public function withdrawAudit(Request $request)
    {
        $this->validate($request, [
            'hall_id' => 'required',//厅ID
            'user_id' => 'required',//用户id
        ]);
        $userId = $request->input('user_id');
        $hallId = $request->input('hall_id');
        $money = $request->input('money'); // 余额
        return WithdrawAuditService::getWithdrawAuditInfo($userId, $hallId, $money);
    }
}
